﻿using ECMessageQueue;
using FESSC_MESSAGE;
using System;
using System.Text;
using System.Windows;

namespace FESSC_WORKBENCH
{
    public class OP_USERLOGIN
    {
        public static void doLogin(string uid, string pwd)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            var pwdm = md5.ComputeHash(Encoding.UTF8.GetBytes(pwd));
            StringBuilder sb = new StringBuilder();
            foreach (var p in pwdm) sb.Append(p.ToString("x2"));
            var loginmsg = new MsgUserLogin(uid, sb.ToString().ToUpper());
            loginmsg.setToken(AppVar.token);
            AppVar.log.Info(loginmsg.ToString());
            AppVar.mqclient.sendMessage(loginmsg.ToString(), AppVar.token);
        }

        public static void doLogout()
        {
            var logoutmsg = new MsgUserLogout(AppVar.uid, true);
            logoutmsg.setToken(AppVar.token);
            AppVar.mqclient.sendMessage(logoutmsg.ToString(), AppVar.token);
        }

        public static void doRequestUserInfo()
        {
            var userinfomsg = new Msg();
            userinfomsg.setHeader("USERINFO", 0, 0);
            userinfomsg.setToken(AppVar.token);
            AppVar.mqclient.sendMessage(userinfomsg.ToString(), AppVar.token);
        }

        public static void doRequestDeptInfo()
        {
            var deptinfomsg = new Msg();
            deptinfomsg.setHeader("DEPTINFO", 0, 0);
            deptinfomsg.setToken(AppVar.token);
            AppVar.mqclient.sendMessage(deptinfomsg.ToString(), AppVar.token);
        }
    }
}
